var pieOption = {
    title : {
        //text: '满意度评价',
        //subtext: '虚构数据，开发中',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient : 'vertical',
        x : 'left',
        data:['未评分','非常差', '差','一般','好','非常好']
    },
    toolbox: {
        show : true,
        feature : {
            //mark : {show: true},
            dataView : {show: true, readOnly: false},
            magicType : {
                show: true,
                type: ['pie', 'funnel'],
                option: {
                    funnel: {
                        x: '25%',
                        width: '50%',
                        funnelAlign: 'left',
                        max: 1548
                    }
                }
            },
            //restore : {show: true},
            //saveAsImage : {show: true}
        }
    },
    calculable : true,
    series : [
        {
            name:'客户评分',
            type:'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:[
                {value:35, name:'未评分'},
                {value:335, name:'非常差'},
                {value:310, name:'差'},
                {value:234, name:'一般'},
                {value:135, name:'好'},
                {value:1548, name:'非常好'}
            ]
        }
    ]
};

$(function () {

    //折叠ibox
    $('.collapse-link').click(function () {
        var ibox = $(this).closest('div.ibox');
        var button = $(this).find('i');
        var content = ibox.find('div.ibox-content');
        content.slideToggle(200);
        button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
        ibox.toggleClass('').toggleClass('border-bottom');
        setTimeout(function () {
            ibox.resize();
            ibox.find('[id^=map-]').resize();
        }, 50);
    });

    //关闭ibox
    $('.close-link').click(function () {
        var content = $(this).closest('div.ibox');
        content.remove();
    });

    //初始化 年月日 6个图表数据
    $.ajaxSettings.async = false;//同步
    $.getJSON('/lgs/main/getEvaluate',function(result){
        sessionStorage.setItem("evaluatePieList", JSON.stringify(result));
    })
    $.ajaxSettings.async = true;//异步

    // var pieGradeMon = echarts.init(document.getElementById("pie_chart_grade_mon"));
    // pieGradeMon.setOption(pieOption);
    // $(window).resize(pieGradeMon.resize);
    // var pieGradeDay = echarts.init(document.getElementById("pie_chart_grade_day"));
    // pieGradeDay.setOption(pieOption);
    // $(window).resize(pieGradeDay.resize);


    layui.use('element', function(){
        var element = layui.element;
        var evaluatePieList = $.parseJSON(sessionStorage.getItem("evaluatePieList"));
        //满意度评价 初始展示年图表
        var pieGradeYear = echarts.init(document.getElementById("pie_chart_grade_year"));
        pieOption.series[0].data = evaluatePieList[0].pieCharts;//data.index 0年、1月、2周
        pieGradeYear.setOption(pieOption);
        window.onresize = pieGradeYear.resize;
        //监听满意度评分切换
        element.on('tab(pieChartGrade)', function(data){
            //var evaluatePieList = $.parseJSON(sessionStorage.getItem("evaluatePieList"));
            var pieGrade;
            if(data.index==0) pieGrade = echarts.init(document.getElementById("pie_chart_grade_year"));
            if(data.index==1) pieGrade = echarts.init(document.getElementById("pie_chart_grade_mon"));
            if(data.index==2) pieGrade = echarts.init(document.getElementById("pie_chart_grade_day"));
            pieOption.series[0].data = evaluatePieList[data.index].pieCharts;//data.index 0年、1月、2周
            pieGrade.setOption(pieOption);
            window.onresize = pieGrade.resize;
        });

        //物流评价 初始展示年图表
        var pieLgsYear = echarts.init(document.getElementById("pie_chart_lgs_year"));
        pieOption.series[0].data = evaluatePieList[3].pieCharts;//data.index 0年、1月、2周
        pieLgsYear.setOption(pieOption);
        window.onresize = pieLgsYear.resize;
        //监听物流评分切换
        element.on('tab(pieChartLgs)', function(data){
            //var evaluatePieList = $.parseJSON(sessionStorage.getItem("evaluatePieList"));
            var pieLgs;
            if(data.index==0) pieLgs = echarts.init(document.getElementById("pie_chart_lgs_year"));
            if(data.index==1) pieLgs = echarts.init(document.getElementById("pie_chart_lgs_mon"));
            if(data.index==2) pieLgs = echarts.init(document.getElementById("pie_chart_lgs_day"));
            pieOption.series[0].data = evaluatePieList[data.index+3].pieCharts;//data.index 0年、1月、2周
            pieLgs.setOption(pieOption);
            window.onresize = pieLgs.resize;
        });
    });

});
